#TODO: url to be refactored ????
from bcat.rpc.client.server_proxy import ServerProxy
from bcat.rpc.client.server_proxy_impl import IServerProxyImpl

class CommonServerProxy(ServerProxy):
    def __init__(self, url: str, impl: IServerProxyImpl):
        super().__init__(url, impl)
        self.__functions = {}
    
    def tick(self) -> str:
        return self.impl().stub().tick()

    def exit(self) -> bool:
        return self.impl().stub().exit()

    def __str__(self):
        return f"url:{self.url()}, {self.__functions}"


import unittest 
from bcat.rpc.client.server_proxy_impls.jsonrpclib_server_proxy_impl import JsonRpcLibServerProxyImpl
class TestCommonServerProxy(unittest.TestCase):
    def test_main(self):
        url = "http://127.0.0.1:80"
        csp = CommonServerProxy(url, JsonRpcLibServerProxyImpl(url))
        print(csp)
        csp.tick()
